
const { removeContent } = require("../service/AuthService");
const {createComment,replyComment,updateComment,removeComment,getCommentList,getDetailComment}=require("../service/CommentService")
class CommentController{
    //创建评论
    async create(ctx,next){
        //获取参数
        const {momentid,content}=ctx.request.body;
        
        const {id}=ctx.user
        console.log(ctx.user)
        //执行service方法
        const result=await createComment(content,momentid,id);
        ctx.body=result;
    }
    //对评论做出评论
    async reply(ctx,next){
         const {momentid,content}=ctx.request.body;
         console.log(momentid)
         console.log(content)
         const {commentid}=ctx.params;
         console.log(commentid)
         const {id}=ctx.user;
         console.log(id)
         const result=await replyComment(content,momentid,id,commentid)
         ctx.body=result;
    }
    async update(ctx,next){
        const {commentid}=ctx.params;
        const {content}=ctx.request.body
        const result=await updateComment(content,commentid)
        ctx.body=result

    }
    //删除评论
    async remove(ctx,next){
        const {commentid}=ctx.params;
        console.log(ctx.user)
       
         const result=  await removeComment(commentid)
        ctx.body=result;
    }
    //获取评论
    async getComment(ctx,next){
        const {momentid}=ctx.query
        const result= await getCommentList(momentid)
        ctx.body=result
    }
    //查看详情
    async getDetail(ctx,next){
        const {momentid}=ctx.params
        console.log(momentid)
        console.log(momentid)
        const result=await getDetailComment(momentid)
    
        ctx.body=result;
    }
}
module.exports=new CommentController(); 